package com.yonyou.hxjy.config;


import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate() {

        CloseableHttpClient httpClient = HttpClients.custom()
                .setMaxConnTotal(100) // 最大连接数
                .setMaxConnPerRoute(20) // 每个路由的最大连接数
                .build();

        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
        requestFactory.setConnectTimeout(5000); // 连接超时时间（毫秒）
        requestFactory.setReadTimeout(5000); // 读取超时时间（毫秒）

        return new RestTemplate(requestFactory);
    }
}
